package com.ruoyi.common.enums.fission;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;

@Getter
@AllArgsConstructor
public enum GroupFissionInviteStatusEnum {

    NOT_JOINED(0, "未入群"),
    JOINED(1, "已进群"),
    LEFT(2, "已退群");

    private final Integer code;
    private final String desc;

    /**
     * 根据code获取枚举
     */
    public static GroupFissionInviteStatusEnum getByCode(Integer code) {
        if (code == null) {
            return null;
        }
        return Arrays.stream(values())
            .filter(status -> status.getCode().equals(code))
            .findFirst()
            .orElse(null);
    }

    /**
     * 根据code获取描述
     */
    public static String getDescByCode(Integer code) {
        GroupFissionInviteStatusEnum status = getByCode(code);
        return status != null ? status.getDesc() : "";
    }

    /**
     * 检查code是否存在
     */
    public static boolean contains(Integer code) {
        return getByCode(code) != null;
    }

    /**
     * 判断是否为有效状态（已进群）
     */
    public boolean isJoined() {
        return this == JOINED;
    }

    /**
     * 判断是否为无效状态（未入群或已退群）
     */
    public boolean isNotValid() {
        return this == NOT_JOINED || this == LEFT;
    }

    /**
     * 是否可以重新邀请（未入群或已退群可以重新邀请）
     */
    public boolean canReinvite() {
        return this == NOT_JOINED || this == LEFT;
    }
}
